<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>教师子系统</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/index.css"/>
    <link href="/layui/css/modules/layer/default/layer.css" rel="stylesheet"/>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header layui-bg-cyan">
        <div class="layui-logo" style="color: #1E9FFF;font-size: 17px;">毕业设计管理系统-教师</div>
        <ul class="layui-nav layui-layout-left" id="nav-title">
            <!--<li class="layui-nav-item"><a href="">课题管理</a></li>-->
            <!--<li class="layui-nav-item"><a href="">用户</a></li>-->
            <li class="layui-nav-item">
                <a href="javascript:;">课题管理</a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" data-url="publish" onclick="clearTopicId()">新建课题</a></dd>
                    <dd><a href="javascript:;" data-url="edit">编辑课题</a></dd>
                    <dd><a href="javascript:;" data-url="check">监控课题流程</a></dd>
                    <dd><a href="javascript:;" data-url="submit">提交审核</a></dd>
                    <dd><a href="javascript:;" onclick="showPlace()">查询答辩场地</a></dd>
                    <!--<dd><a href="javascript:;">授权管理</a></dd>-->
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child" id="otherRole">
                    <dd><a href="/admin">管理员</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="javascript:;">论文管理</a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" onclick="readTopic()">接收论文</a></dd>
                    <dd><a href="javascript:;" onclick="backTopic()">批复论文</a></dd>

                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="/image/avatar/inspectocat.jpg" class="layui-nav-img"/>
                    <span id="nameT"></span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" onclick="base()">基本资料</a></dd>
                    <!--<dd><a href="">安全设置</a></dd>-->
                    <dd><a href="javascript:;" onclick="logout()">注销登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div class="layui-body main-body main-body-teacher">
        <!-- 内容主体区域 -->
        <iframe src="/teacher/init.html" style="width:100%;height:100%;" id="main_page"></iframe>
    </div>
    <div class="layui-footer footer-teacher">
        © kuangcp.top
    </div>
</div>
</body>
<script src="/js/jquery.min.js"></script>
<script src="/js/common/main-page.js"></script>
<script src="/layui/lay/modules/layer.js"></script>
<script src="/js/config/server.js"></script>
<script src="/js/common/login.js"></script>
<script src="/layui/layui.all.js"></script>
<script>
  home('teacher');
  getTeacher('/' + sessionStorage.getItem('teacherId'), function (data) {
    $("#nameT").html(data.data.username);
  }, function (data) {
  });
  getRole();

  // 绑定点击事件
  $(function () {
    $("[data-url]").on('click', function () {
      turn('teacher', $(this).data('url'))
    });
  });
  // 实例化后台界面的组件
  layui.use('element', function () {
    var element = layui.element;
  });

  function clearTopicId() {
    sessionStorage.removeItem('editId');
  }

  function base() {
    getTeacher('/' + sessionStorage.getItem('teacherId'), function (data) {
      var content = $("#profile").html();
      content = content.replace('username##VA', data.data.username);
      content = content.replace('teacherNo##VA', data.data.teacherNo);
      content = content.replace('email##VA', data.data.email);
      tip('个人资料', content);
    });
  }

  function tip(title, content) {
    return layer.open({
      title: title
      , type: 1
      , content: content
      , btnAlign: 'c'
      , resize: true
      , tipsMore: true
      , area: ['200px', '200px']
      // , btn: ['确认', '取消']
      , yes: function (index, layero) {
      },
      cancel: function () {
      }
    });
  }
  function frameTip(title, url) {
    layer.open({
      title: title
      , type: 2
      , content: url
      , btnAlign: 'c'
      , resize: true
      , tipsMore: true
      , area: ['600px', '300px']
      ,cancel: function () {
        sessionStorage.removeItem('editTeamId');
        sessionStorage.removeItem('editCollege');
        sessionStorage.removeItem('editMajor');
        sessionStorage.removeItem('editJudge');
        // reloadAll();
      }
    });
  }

  function getRole() {
    if (sessionStorage.getItem('teacherId') !== null && sessionStorage.getItem('WHO') === null) {
      getTeacher('/roles/' + sessionStorage.getItem('teacherId'), function (data) {
        if (data.code === '0') {
          sessionStorage.setItem('WHO', data.data);
          showRole();
        }
      });
    }
    if (sessionStorage.getItem('WHO') !== null) {
      showRole()
    }
  }

  function showRole() {
    var temp = sessionStorage.getItem('WHO');
    var roles = temp.split("#");
    roles.forEach(function (value) {
      if (value === 'LEADER') {
        $("#otherRole").append('<dd><a href="leader">负责人</a></dd>')
      }
      if (value === 'SECRETARY') {
        $("#otherRole").append('<dd><a href="secretary">答辩秘书</a></dd>')
      }
    })
  }
  function showPlace() {
    handlerGet('/bus/teacher/query/place/'+sessionStorage.getItem('teacherId'), 'teacher',  function (data) {
      console.log(data);
      if(data.code === '401'){
        tip('答辩场地', '暂无安排')
      }else{
        // TODO 场地的格式
        tip('答辩场地', data.data);
      }
    }, function (data) {
      layer.msg('请检查网络连接并重试'+data.responseText);
    });
  }
  // TODO 回复
  function readTopic() {
    frameTip('接收论文', 'module/readDoc.html')
  }
  function backTopic() {
    frameTip('批复论文', 'module/backDoc.html')

  }
</script>
<script type="text/html" id="profile">
    <i class="layui-icon" style="font-size: 25px; color: #1E9FFF;">&#xe612;</i>
    <label>姓名：</label>
    <label>username##VA</label>
    <hr>
    <i class="layui-icon" style="font-size: 25px; color: #1E9FFF;">&#xe60b;</i>
    <label>工号：</label>
    <label>teacherNo##VA</label>
    <hr>
    <i class="layui-icon" style="font-size: 25px; color: #1E9FFF;">&#xe609;</i>
    <label>邮箱：</label>
    <label>email##VA</label>
</script>

</html>